package dao.impl;

import dao.LoverDao;
import domain.Lover;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import util.JDBCUtils;

import java.util.List;

public class LoverDaoImpl implements LoverDao {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());

    //用户喜爱度统计
    @Override
    public List<Lover> SelectLoverByTelephone(String telephone) {
        String sql = "SELECT B.name,B.telephone,A.contact_id2,C.name,A.call_duration_count AS loverCount FROM tb_intimacy A LEFT JOIN tb_contacts B ON A.contact_id1 = B.id LEFT JOIN tb_contacts C ON A.contact_id2 = C.id WHERE B.telephone = "+telephone+" ORDER BY A.call_duration_count";
        List<Lover> lovers = template.query(sql, new BeanPropertyRowMapper<Lover>(Lover.class));
        return lovers;
    }
}
